#!/usr/bin/python
# -*- coding: utf-8 -*-

class ObjectLog:

    def __init__ (self, object_id, instances = {}):

        self._object_id = object_id
        self._instances = instances

        self._satisfaction_degree = 1.0

    def is_associated_instace (self, inst):
        
        if self._instances.has_key(inst._constraint_id):
            return True
        else:
            return False

    def add_instance (self, key, inst):
        
        self._instances[key] = inst

    def remove_instance (self, key):

        try:
            self._instances.pop(key)
        except KeyError:
            pass

    def update_satisfaction_degree (self):

        max_value = 0.0

        for ins in self._instances.values():
            ins.update_satisfaction_degree()

        for ins in self._instances.values():

            ins.update_satisfaction_degree()
            aux = ins._satisfaction_degree
            if aux > max_value:
                max_value = aux

        self._satisfaction_degree = max_value

    def __str__ (self):

        aux = 'Object_ID: ' + self._object_id + '\n'

        for i in self._instances.values():
            aux += str(i)

        aux += ('Global satisfaction degree: ' + str(self._satisfaction_degree))

        return aux
